import tempfile
import subprocess
import pathlib


def main():
    proto = pathlib.Path(__file__).parent.parent / "protos/example.proto"
    with tempfile.TemporaryDirectory() as td:
        cmd = [
            "protoc",
            f"--plugin=protoc-gen-napi={pathlib.Path(__file__).parent.parent}/protoc-gen-napi",
            f"--napi_out={td}",
            f"-I{pathlib.Path(__file__).parent.parent}/protos",
            str(proto),
        ]
        print(cmd)
        subprocess.run(cmd, check=True)
        print((pathlib.Path(td) / "example.napi.h").read_text())
        print((pathlib.Path(td) / "example.napi.cc").read_text())
        assert (pathlib.Path(td) / "example.napi.cc").exists()


if __name__ == "__main__":
    main()
